<script type="text/javascript">
$(document).ready(function(){   
        $('.simplemodal-wrap').css('overflow', 'auto'); // or try jQuery.modal.update();
});
</script>
<div class="grid_container">
	<div class="grid_12">
		<div class="widget_wrap">
			<div class="widget_top">
				<span class="h_icon clipboard"></span>
				<h6>Kardex Por Producto</h6>
			</div>
                        </br>
                        </br>      
			<div class="widget_content">                           
                        <ul>
                        <li> 
                            <div class="form_grid_12">
                                <label style="size: 40px;margin-right: 100px;" class="field_title" for="rs"><strong>Almacén : </strong><?echo $namewarehouse->name;?></label>
                            <label class="field_title" for="rs">Del <?echo $desde;?> Hasta <?echo $hasta;?></label>
                            </br>
                            </br>
                            <label class="field_title" for="rs"><strong>Producto:</strong> <?echo $code;?> - <?echo $product->description;?> </label>
                            </br>
                            </br>
                            <label class="field_title" for="rs"><strong>Caja x: </strong> <?echo $product->box_packs+" ";?> Bolsas</label>
                            </div>                            
                        </li>                            
                        </ul>
                        </div>
                        <span class="clear"></span>
				<table border="1" rules="cols" class="wtbl_list" id="table1">
                                    </br>
                                    </br>
					<thead>
						<tr>
						<th colspan="3"></th>
                                                <th colspan="3">Ingresos</th>
                                                <th colspan="3">Salidas</th>
                                                <th colspan="3">Saldo</th>
						</tr>
                                                <tr>
                                                <th>Fecha</th>
                                                <th>Documento</th>
						<th>Cliente</th>                                                
                                                <th style="border-left: 1px solid black;">Cajas</th>
						<th>Empaques</th>
						<th>Unidades</th>                                                
                                                <th style="border-left: 1px solid black;">Cajas</th>
						<th>Empaques</th>
						<th>Unidades</th>                                                
                                                <th style="border-left: 1px solid black;">Cajas</th>
						<th>Empaques</th>
						<th>Unidades</th>                                                
                                                </tr>
					</thead>
					<tbody>
					<?php $i = 0; ?>
					<?php foreach ($kardex as $p) : ?>
					    <?php $i++; ?>
						<tr class="<?=($i%2==0) ? "tr_even" : "tr_odd" ?>">
							<td align="center"><?=$p->date; ?></td>
                                                        <? if($p->document_type_id == 3)
                                                        {
                                                            ?>
                                                            <td align="center"><? echo "GC ".$p->document_code; ?></td>
                                                            <?
                                                        }
                                                        else if($p->document_type_id == 4)
                                                        {
                                                            ?>
                                                            <td align="center"><? echo "GV ".$p->document_code; ?></td>
                                                            <?
                                                        }
                                                        else if($p->document_type_id == 5)
                                                        {
                                                            ?>
                                                            <td align="center"><? echo "GR ".$p->document_code; ?></td>
                                                            <?
                                                        }
                                                            
                                                        if($p->document_type_id == 5)
                                                        {
                                                            ?>
                                                            <td align="center"><? echo "Traslado" ?></td>
                                                            <?
                                                        }
                                                        else
                                                        {
                                                            ?>
                                                            <td align="center"><?=$p->client; ?></td>
                                                            <?
                                                        }
                                                            ?>                                                         
							<? if($p->document_type_id == 3)
                                                        {
                                                            ?>
                                                        <td style="border-left: 1px solid black;" align="center"><input id="box_i_<?echo $i?>" type="hidden" value="<?=$p->box ?>"><?=$p->box ?></td>
							<td align="center"><input id="pack_i_<?echo $i?>" type="hidden" value="<?=$p->pack; ?>"><?=$p->pack; ?></td>
							<td align="center"><input id="unit_i_<?echo $i?>" type="hidden" value="<?=$p->unit; ?>"><?=$p->unit; ?></td>
                                                        <td style="border-left: 1px solid black;" align="center">-</td>
							<td align="center">-</td>
							<td align="center">-</td>
                                                        <script>
                                                        
                                                        function operacion<?echo $i?>(){                                                          
                                                        var boxi = parseInt($('#box_i_<?echo $i?>').val());
                                                        var packi = parseInt($('#pack_i_<?echo $i?>').val());
                                                        var uniti = parseInt($('#unit_i_<?echo $i?>').val());
                                                        var i= parseInt(<?echo $i?>);
                                                        //alert(i);
                                                        if(i==1)
                                                        {
                                                        //var boxs_a = parseInt(<?/*echo $scajas?>);
                                                        //var packs_a = parseInt(<?echo $spaquetes?>);
                                                        //var unitss_a = parseInt(<?echo $sunidades*/?>);
                                                        var boxs_a = parseInt(0);
                                                        var packs_a = parseInt(0);
                                                        var unitss_a = parseInt(0);
                                                        }
                                                        else
                                                        {
                                                        var boxs_a = parseInt($('#box_s_td_<?echo ($i-1)?>').html());
                                                        var packs_a = parseInt($('#pack_s_td_<?echo ($i-1)?>').html());
                                                        var unitss_a = parseInt($('#unit_s_td_<?echo ($i-1)?>').html());
                                                        }
                                                        var boxs = parseInt(boxi+boxs_a);
                                                        var packs = parseInt(packi+packs_a);
                                                        var unitss = parseInt(uniti+unitss_a);
                                                        //alert(boxs);
                                                        //alert(packs);
                                                        //alert(unitss);
                                                        $('#box_s_td_<?echo $i?>').html(boxs);
                                                        $('#pack_s_td_<?echo $i?>').html(packs);
                                                        $('#unit_s_td_<?echo $i?>').html(unitss);
                                                        
                                                        }                              
                                                       
                                                        
                                                        </script>
                                                        <?
                                                        }
                                                        else if ($p->document_type_id == 4){
                                                            ?>
                                                        <td style="border-left: 1px solid black;" align="center"><input id="box_i_<?echo $i?>" type="hidden" value="0">-</td>
							<td align="center"><input id="pack_i_<?echo $i?>" type="hidden" value="0">-</td>
							<td align="center"><input id="unit_i_<?echo $i?>" type="hidden" value="0">-</td>
                                                        <td style="border-left: 1px solid black;" align="center"><input id="box_o_<?echo $i?>" type="hidden" value="<?=$p->box ?>"><?=$p->box ?></td>
							<td align="center"><input id="pack_o_<?echo $i?>" type="hidden" value="<?=$p->pack; ?>"><?=$p->pack; ?></td>
							<td align="center"><input id="unit_o_<?echo $i?>" type="hidden" value="<?=$p->unit; ?>"><?=$p->unit; ?></td>
                                                        <script>
                                                        
                                                        function operacion<?echo $i?>(){                                                          
                                                        var boxo = parseInt($('#box_o_<?echo $i?>').val());
                                                        var packo = parseInt($('#pack_o_<?echo $i?>').val());
                                                        var unito = parseInt($('#unit_o_<?echo $i?>').val());
                                                        var i= parseInt(<?echo $i?>);
                                                        //alert(i);
                                                        if(i==1)
                                                        {
                                                        //var boxs_a = parseInt(<?/*echo $scajas?>);
                                                        //var packs_a = parseInt(<?echo $spaquetes?>);
                                                        //var unitss_a = parseInt(<?echo $sunidades*/?>);
                                                        var boxs_a = parseInt(0);
                                                        var packs_a = parseInt(0);
                                                        var unitss_a = parseInt(0);
                                                        }
                                                        else
                                                        {
                                                        var boxs_a = parseInt($('#box_s_td_<?echo ($i-1)?>').html());
                                                        var packs_a = parseInt($('#pack_s_td_<?echo ($i-1)?>').html());
                                                        var unitss_a = parseInt($('#unit_s_td_<?echo ($i-1)?>').html());
                                                        }
                                                        var boxs = parseInt(boxs_a-boxo);
                                                        var packs = parseInt(packs_a-packo);
                                                        var unitss = parseInt(unitss_a-unito);
                                                        //alert(boxs);
                                                        //alert(packs);
                                                        //alert(unitss);
                                                        $('#box_s_td_<?echo $i?>').html(boxs);
                                                        $('#pack_s_td_<?echo $i?>').html(packs);
                                                        $('#unit_s_td_<?echo $i?>').html(unitss);
                                                        
                                                        
                                                        }                              
                                                        
                                                        
                                                        </script>
                                                        <?                                                                
                                                        }
                                                        else if ($p->document_type_id == 5){							
                                                        if($p->client != $id_warehouse)
                                                        {
                                                            ?>
                                                        <td style="border-left: 1px solid black;" align="center"><input id="box_i_<?echo $i?>" type="hidden" value="<?=$p->box ?>"><?=$p->box ?></td>
							<td align="center"><input id="pack_i_<?echo $i?>" type="hidden" value="<?=$p->pack; ?>"><?=$p->pack; ?></td>
							<td align="center"><input id="unit_i_<?echo $i?>" type="hidden" value="<?=$p->unit; ?>"><?=$p->unit; ?></td>
                                                        <td style="border-left: 1px solid black;" align="center">-</td>
							<td align="center">-</td>
							<td align="center">-</td>
                                                        <script>
                                                        
                                                        function operacion<?echo $i?>(){                                                          
                                                        var boxi = parseInt($('#box_i_<?echo $i?>').val());
                                                        var packi = parseInt($('#pack_i_<?echo $i?>').val());
                                                        var uniti = parseInt($('#unit_i_<?echo $i?>').val());
                                                        var i= parseInt(<?echo $i?>);
                                                        //alert(i);
                                                        if(i==1)
                                                        {
                                                        //var boxs_a = parseInt(<?/*echo $scajas?>);
                                                        //var packs_a = parseInt(<?echo $spaquetes?>);
                                                        //var unitss_a = parseInt(<?echo $sunidades*/?>);
                                                        var boxs_a = parseInt(0);
                                                        var packs_a = parseInt(0);
                                                        var unitss_a = parseInt(0);
                                                        }
                                                        else
                                                        {
                                                        var boxs_a = parseInt($('#box_s_td_<?echo ($i-1)?>').html());
                                                        var packs_a = parseInt($('#pack_s_td_<?echo ($i-1)?>').html());
                                                        var unitss_a = parseInt($('#unit_s_td_<?echo ($i-1)?>').html());
                                                        }
                                                        var boxs = parseInt(boxi+boxs_a);
                                                        var packs = parseInt(packi+packs_a);
                                                        var unitss = parseInt(uniti+unitss_a);
                                                        //alert(boxs);
                                                        //alert(packs);
                                                        //alert(unitss);
                                                        $('#box_s_td_<?echo $i?>').html(boxs);
                                                        $('#pack_s_td_<?echo $i?>').html(packs);
                                                        $('#unit_s_td_<?echo $i?>').html(unitss);
                                                        
                                                        }                              
                                                       
                                                        
                                                        </script>
                                                        <?
                                                        }
                                                        else {
                                                            ?>
                                                        <td style="border-left: 1px solid black;" align="center"><input id="box_i_<?echo $i?>" type="hidden" value="0">-</td>
							<td align="center"><input id="pack_i_<?echo $i?>" type="hidden" value="0">-</td>
							<td align="center"><input id="unit_i_<?echo $i?>" type="hidden" value="0">-</td>
                                                        <td style="border-left: 1px solid black;" align="center"><input id="box_o_<?echo $i?>" type="hidden" value="<?=$p->box ?>"><?=$p->box ?></td>
							<td align="center"><input id="pack_o_<?echo $i?>" type="hidden" value="<?=$p->pack; ?>"><?=$p->pack; ?></td>
							<td align="center"><input id="unit_o_<?echo $i?>" type="hidden" value="<?=$p->unit; ?>"><?=$p->unit; ?></td>
                                                        <script>
                                                        
                                                        function operacion<?echo $i?>(){                                                          
                                                        var boxo = parseInt($('#box_o_<?echo $i?>').val());
                                                        var packo = parseInt($('#pack_o_<?echo $i?>').val());
                                                        var unito = parseInt($('#unit_o_<?echo $i?>').val());
                                                        var i= parseInt(<?echo $i?>);
                                                        //alert(i);
                                                        if(i==1)
                                                        {
                                                        //var boxs_a = parseInt(<?/*echo $scajas?>);
                                                        //var packs_a = parseInt(<?echo $spaquetes?>);
                                                        //var unitss_a = parseInt(<?echo $sunidades*/?>);
                                                        var boxs_a = parseInt(0);
                                                        var packs_a = parseInt(0);
                                                        var unitss_a = parseInt(0);
                                                        }
                                                        else
                                                        {
                                                        var boxs_a = parseInt($('#box_s_td_<?echo ($i-1)?>').html());
                                                        var packs_a = parseInt($('#pack_s_td_<?echo ($i-1)?>').html());
                                                        var unitss_a = parseInt($('#unit_s_td_<?echo ($i-1)?>').html());
                                                        }
                                                        var boxs = parseInt(boxs_a-boxo);
                                                        var packs = parseInt(packs_a-packo);
                                                        var unitss = parseInt(unitss_a-unito);
                                                        //alert(boxs);
                                                        //alert(packs);
                                                        //alert(unitss);
                                                        $('#box_s_td_<?echo $i?>').html(boxs);
                                                        $('#pack_s_td_<?echo $i?>').html(packs);
                                                        $('#unit_s_td_<?echo $i?>').html(unitss);
                                                        
                                                        
                                                        }                              
                                                        
                                                        
                                                        </script>
                                                        <?                                                                                                                                                                                                                                                                       
                                                        }
                                                        }
                                                        ?>
                                                        <td style="border-left: 1px solid black;" id="box_s_td_<?echo $i?>" align="center"></td>
							<td id="pack_s_td_<?echo $i?>" align="center"></td>
							<td id="unit_s_td_<?echo $i?>" align="center"></td>
						</tr>
                                                
					<?php endforeach; ?>
                                                <script>
                                                    $(document).ready( function() 
                                                        {   for(i=1;i<=<?echo $i?>;i++)
                                                                {
                                                                    var op ="operacion";
                                                                    var num = i;
                                                                    var fun ="();";
                                                                    var funcion = op.concat(num,fun);
                                                                    eval(funcion);
                                                                }                                                                                                                          
                                                        } );
                                                   
                                                </script>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<span class="clear"></span>
</div>